//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口;

import java.util.HashMap;

public class demo_567 {
	public demo_567() {
	}

	public static void main(String[] args) {
		System.out.println(checkInclusion("ab", "eidbaooo"));
	}

	public static boolean checkInclusion(String s1, String s2) {
		int n = s2.length();
		int k = s1.length();
		int left = 0;
		char[] chars1 = s1.toCharArray();
		char[] chars2 = s2.toCharArray();
		HashMap<Character, Integer> s1Map = new HashMap();

		for(char c : chars1) {
			s1Map.put(c, (Integer)s1Map.getOrDefault(c, 0) + 1);
		}

		for(int i = 0; i < n; ++i) {
			char c = chars2[i];
			if (s1.indexOf(c) != -1) {
				s1Map.put(c, (Integer)s1Map.getOrDefault(c, 0) - 1);
				if ((Integer)s1Map.get(c) == 0) {
					s1Map.remove(c);
				}
			}

			if (i >= k - 1) {
				if (s1Map.isEmpty()) {
					return true;
				}

				char out = chars2[left];
				if (s1.indexOf(out) != -1) {
					s1Map.put(out, (Integer)s1Map.getOrDefault(out, 0) + 1);
					if ((Integer)s1Map.get(out) == 0) {
						s1Map.remove(out);
					}
				}

				++left;
			}
		}

		return false;
	}
}
